dojo.provide('ph.osc');

dojo.require('ph.osc.Receiver');
dojo.require('ph.osc.Sender');

ph.osc._receivers = {};
ph.osc.getReceiver = function(port) {
  if (!this._receivers[port]) {
    this._receivers[port] = new ph.osc.Receiver(port);
    this._receivers[port].start();
  }
  
  return this._receivers[port];
};

ph.osc.subscribe = function(port, topic, context, method) {
  if (!method && typeof(context) == 'function') {
    method = context;
    context = null;
  }
  return this.getReceiver(port).subscribe(topic, context, method);
};

ph.osc.publish = function(host, port, topic) {
  var sender = new ph.osc.Sender(host, port);
  var args = Array.slice(arguments, 2);
  return sender.send.apply(sender, args);
};